/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ShowCuenta.java
 *
 * Created on Dec 13, 2011, 10:55:48 AM
 */

package INTERFAZ;
import CONTROLES.ControlSucursal;
import CONTROLES.ControlCliente;
import CONTROLES.ControlEmpleado;
import CONTROLES.ControlEmpleo;
import CONTROLES.ControlUsuario;
import MODELOS.Cliente;
import MODELOS.Empleado;
import MODELOS.Empleo;
import MODELOS.Permisos;
import MODELOS.Usuario;
import UTILITARIOS.Herramienta;
import UTILITARIOS.MiModelo;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author VICENTE
 */
public class permisosSuperUsu extends JDialog {

    /** Creates new form ShowCuenta */

    ControlSucursal control = new ControlSucursal();
    String lista[] = control.nombresSuc();
    ControlEmpleo cEmp = new ControlEmpleo();


    public permisosSuperUsu(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        setAlwaysOnTop(false);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
       // this.cliente = c;
        initComponents();
        cambiarPropiedades();
        setResizable(false);
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        activas = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("PERMISOS DE SUPERUSUARIO");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                dispose(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ACCIONES", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jButton2.setText("Habilitar SuperUsuario");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(106, 106, 106)
                .addComponent(jButton2)
                .addContainerGap(102, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jButton2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ADMINISTRADORES", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 51, 102))); // NOI18N

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 10))); // NOI18N

        activas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                activasMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(activas);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 559, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(58, 58, 58))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 587, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(151, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(149, 149, 149))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void dispose(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_dispose
        addWindowListener( new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e) {
				//JOptionPane.showMessageDialog(null, "Seguro que quiere salir", "Adventencia", JOptionPane.OK_OPTION);
                                //System.exit(0);
                            dispose();
                        }
		});
    }//GEN-LAST:event_dispose

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        ControlUsuario c_usu = new ControlUsuario();
        ControlEmpleado c_empleado = new ControlEmpleado();
        

        ArrayList<Permisos> permisos = c_empleado.getAdminPermisos();
        System.out.println("tamano: "+permisos.size());
         for(int i=0; i<permisos.size(); i++){
                    System.out.println("ubicacion: "+i);
                    
                    boolean per = ((Boolean) activas.getValueAt(i, 4)).booleanValue();
                    System.out.println("id del usuario: "+permisos.get(i).getIdUs());
                    System.out.println("permiso del usuario: "+per);

                    
                    Usuario c_1 = c_usu.getUsuarioPermiso(permisos.get(i).getIdUs());
                    c_1.setPermiso(per);
                    
                   if(per == true){
                    c_usu.habilitarSuperUsuario(this,c_1);
                   
                    }else{
                    c_usu.deshabilitarSuperUsuario(this,c_1);

                    }
           }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void activasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_activasMouseClicked
        jButton2.setEnabled(true);
    }//GEN-LAST:event_activasMouseClicked

    /**
    * @param args the command line arguments
    */
    private void cambiarPropiedades(){
       
        jButton2.setEnabled(false);

        
        MiModelo modelo_activas = new MiModelo(new Object [][] {},new String [] {"ID","Nombre", "Apellidos","Usuario", "Permiso"},4);
        ControlEmpleado c_empleado = new ControlEmpleado();

        ArrayList<Permisos> permisos = new ArrayList<Permisos>();
        
        permisos = c_empleado.getAdminPermisos();
        
        if(permisos.size()>0){
            for(int i=0;i<permisos.size();i++){
                Object [] auxEmpleado = {permisos.get(i).getIdUs(),permisos.get(i).getNombre(),permisos.get(i).getApellido(),permisos.get(i).getNombreUs(),permisos.get(i).isPermiso()};
                modelo_activas.addRow(auxEmpleado);
            }
        }        
        activas.setModel(modelo_activas);        
               
    }

    public static void main(String args[]) {
        
        permisosSuperUsu dialog = new permisosSuperUsu(new javax.swing.JFrame(), true);
        dialog.setVisible(true);
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable activas;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

    private Cliente cliente;


    

    public String getEstado(boolean est)
        {
           String res="";
            if(est == true)
                res = "Activo";
            else
                res = "Inactivo";
            return res;
        }

    
    
    
     
}







    

